class RefactorHouseVisits < ActiveRecord::Migration
  def self.up
    create_table :entrances do |t|
      t.column :entrance_time, :datetime, :null => false
      t.column :recorded_at, :datetime, :null => false
      t.column :recorded_by, :integer, :null =>  false
    end
    create_table :exits do |t|
      t.column :exit_time, :datetime, :null => false
      t.column :recorded_at, :datetime, :null => false
      t.column :recorded_by, :integer, :null =>  false
      t.column :destination, :string, :null => false
    end    
    remove_column :house_visits, :enter_time
    remove_column :house_visits, :exit_time
    remove_column :house_visits, :destination
    remove_column :house_visits, :enter_recorded_at
    remove_column :house_visits, :exit_recorded_at
    add_column :house_visits, :entrance_id, :integer, :null => true
    add_column :house_visits, :exit_id, :integer, :null => true   
  end

  def self.down
    drop_table :entrances
    drop_table :exits
    add_column :house_visits, :enter_time, :datetime, :null => false
    add_column :house_visits, :exit_time, :datetime, :null => true
    add_column :house_visits, :destination, :string, :null => false
    add_column :house_visits, :enter_recorded_at, :datetime, :null => false
    add_column :house_visits, :exit_recorded_at, :datetime, :null => true
    remove_column :house_visits, :entrance_id
    remove_column :house_visits, :exit_id
  end
end
